from django.shortcuts import render

# Create your views here.
from django.views.generic import ListView
from rest_framework.generics import RetrieveAPIView, ListAPIView
from rest_framework_extensions.cache.mixins import ListCacheResponseMixin, RetrieveCacheResponseMixin

from areas.models import Area
from areas.serializers import AreaSerializer, SubAreaSerializer


class AreaProvinceView(ListCacheResponseMixin, ListAPIView):
    # 查询所有的省份
    queryset = Area.objects.filter(parent=None)  # 所有的省份
    serializer_class = AreaSerializer
    # 禁用分页功能
    paginator_class = None


class SubAreaView(RetrieveCacheResponseMixin, RetrieveAPIView):
    # 查询一个区域（城市和区县）
    queryset = Area.objects.all()
    serializer_class = SubAreaSerializer
